package com.ys.servers.common.data;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import io.vertx.core.json.JsonObject;


/**
 * Created by taotao on 2017/5/5
 *
 */
public abstract class DataEntity {


    @JSONField(name = "_id")
    private String id;

    public JsonObject toDataObject() {
        return new JsonObject(JSON.toJSONString(this));
    }

    public static <T> T parseJsonObject(JsonObject dataObject, Class<T> clazz) {
        return JSON.parseObject(dataObject.encode(), clazz);
    }



    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public static <T> T parseString(String jsonString, Class<T> clazz) {
        return JSON.parseObject(jsonString, clazz);
    }

    public String toString() {
        return JSON.toJSONString(this);
    }


    /**
     * Added by xingyt
     * DataEntity如果需要加入缓存排序列表，可以override该方法
     * @return
     */
    public double getScore(){
        return 0;
    }


}
